Skip to content

fix(studio): a sealed gesture recording keeps the layer's offset and the film's scale - #8568

Merged
miguel-heygen merged 6 commits into
mainfrom
fix/sealed-recording-reads-frame
Nov 23, 2026
Merged

miguel-heygen merged 6 commits into
mainfrom
fix/sealed-recording-reads-frame

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

On a sealed preview, a recorded gesture now starts from the layer's real GSAP position and scales the pointer by the film's own width. While it records, the film's playhead moves, so the recording stops by itself at the layer's end. Before, a sealed recording started from 0/0 on an assumed 1920-wide film. The saved keyframes dropped the layer's offset and were the wrong size on any film that isn't 1920 wide, the playhead never moved, and it ran until stopped by hand. "Recorded N keyframes" still showed.

Why

useGestureRecording read the frame directly:

  • base x, y, opacity and scale through iframe.contentWindow.gsap, which a sealed frame doesn't expose, so a catch left 0/0/1/1;
  • the film width through contentDocument, which is null, so it fell back to 1920.

With no in-frame runtime it also never moved the playhead, and the auto-stop in useGestureCommit watches the playhead.

Related work

Refs #7846 (Studio's preview sealed by default).

How

  • Base values, frame (editingGestureStart.ts, editingPort.ts): a new gesture-base request answers GSAP's x, y, opacity and scaleX for each handle, animated or static, the same gsap.getProperty reads the unsealed recorder makes. It's its own request, not an option on gesture-start: that read deliberately never asks GSAP about a layer no tween touches, because asking GSAP for x folds a CSS translate into its transform, and the next drag would then read the layer as GSAP-owned. Only a recording asks, as it does unsealed.
  • Base values, Studio: on a sealed preview useGestureCommit asks gesture-base for the selection's handle (previewGestureBase) and starts the recording from that answer. Unsealed reads the live GSAP through getIframeGsap and starts in the same task, as before.
  • Film width: on a sealed preview, from previewStageSize, the size the frame's runtime posts. Unsealed reads the composition's data-width as before.
  • Playhead: a sealed recording asks the player to seek to the recording's time, up to the layer's end (requestSeek, the same seek the timeline uses). The film moves, the playhead follows, and the existing auto-stop fires.
  • Recorded time: samples stop at the layer's end too, so a recording can't outlast what the playhead shows before the auto-stop sees it. A sample snapped to the nearest frame never lands past that end: when rounding would pass it, the sample takes the frame before. This applies unsealed as well, where only the runtime's seek was capped.
  • A late answer: a sealed start that waits for gesture-base starts only if, when the answer lands, it's still the latest start, the same preview frame, the same layer, Studio is still mounted, and the preview hasn't turned read-only.
  • Refusal: when the frame can't report the layer's values (an older runtime has no gesture-base) or the film's size, the recording doesn't start, and Studio shows "Preview not ready. Try again", the message it already shows when there's no preview. It never records from defaults.
  • An unsealed preview doesn't change.
  • Producer size budget (scripts/package-size-budgets.json): gesture-base ships in the runtime the producer bundles, adding 319 bytes to its unpacked size. Measured on Linux with pnpm pack, main's producer is 3,526,003 bytes unpacked, 265 bytes under the 1% tolerance over its 3,491,355 budget, so any runtime change past that fails the check. The budget moves to 3,702,639, which is the script's own 5% headroom over this branch's 3,526,322. The packed budget doesn't change (977,466 against 993,551).

No visible change

On a sealed preview, recording a gesture saves the motion where the layer is and at the film's scale, and stops at the layer's end. The interface itself doesn't change.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix:

  • packages/studio/src/hooks/useGestureRecording.sealed.test.tsx: "starts from the layer's GSAP offset the frame reported", "scales the pointer by the film's own width, not 1920", "moves the film's playhead with the recording, up to the layer's end, so auto-stop can fire", "refuses to record when the frame hasn't reported the layer's values", "refuses to record when the frame hasn't reported the film's size", "scales from a static scale the same sealed as unsealed";
  • packages/studio/src/hooks/useGestureCommit.test.tsx: "doesn't start once another layer is selected before the frame answers", "doesn't start once Studio unmounts before the frame answers";
  • packages/studio/src/hooks/useGestureRecording.sealed.test.tsx: "saves no sample past a layer end that falls between frames" (a layer ending at 2.52 s, recorded from 2 s at 30 fps: the last sample is 0.5 s; before, rounding saved 0.533 s);
  • packages/core/src/runtime/editingGestureStart.test.ts: "reads GSAP's x, y, opacity and scale for a layer no tween touches", "answers null without GSAP, or for an element this load does not have".

useGestureCommit.test.tsx and newTweenTargetHooks.test.tsx mock the recorder; their mock's start now answers that it started.

  • The playhead row also checks the last sample lands at the layer's end (0.5 s into a recording from 2 s on a layer ending at 2.5 s); against the previous head it recorded 0.9 s.
  • With the fix, useGestureRecording.sealed.test.tsx, useGestureRecording.test.tsx, useGestureCommit.test.tsx, newTweenTargetHooks.test.tsx (33 tests) and editingGestureStart.test.ts (19 tests) pass three runs in a row on Linux. Against main's sources the six recorder rows and the two gestureBase rows fail.
  • Core src/runtime (164 files, 3,597 tests) passes, with gesture-base added to the request lists in editingAgent.test.ts and editingPort.test.ts. Core and Studio typecheck clean.
  • Studio src/hooks and src/components/editor (4,047 tests) pass with the review fixes. In the full run before it, every file passed but Timeline.virtualization.test.tsx, whose 11 tests failed in the full parallel run (one timed out at 31 s). The file passes 11/11 run alone, twice with this branch and once on main's sources; this branch doesn't touch the timeline.
  • Not covered: a sealed recording still doesn't move the layer itself while recording (the recorder's live preview needs the in-frame runtime). It's its own follow-up row.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 48 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (2)

  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true
  • seqab-none-pct-r0-root-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Revalidate the target after the sealed frame answers. useGestureCommit.ts:442 starts an asynchronous base read, but its completion calls begin with the captured selection and iframe. If the user switches layers, reloads the frame, leaves the project, or enters read-only mode before the reply, that callback can still start recording. It can pair the old target with the current selection’s animation list, or attach document listeners after the hook has unmounted. Invalidate the pending start on those changes and check the current preview and target before arming it. Add a deferred-reply test through the commit hook.

P2 — Clamp the recorded samples at the layer end. useGestureRecording.ts:440–445 caps only the seek. The sample still uses elapsed wall time, until the separate stop interval observes the seek. A recording started at 2 s on a layer ending at 2.5 s can seek to 2.5 s but save a 0.9 s sample. The commit uses that last sample as its duration. The new test checks the seek alone. Please cap the saved samples and assert the resulting recording duration.

Static review.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Both fixed in 8c9abab.

  • Stale start: the sealed start now carries a token. Starting again, turning the preview read-only, or unmounting the hook invalidates it, and when gesture-base answers, recording starts only if the token is still current, the preview frame is the same and the selection is still the same layer. New rows in useGestureCommit.test.tsx defer the frame's answer through the commit hook: "doesn't start once another layer is selected before the frame answers" and "doesn't start once Studio unmounts before the frame answers". Both fail on 123c67a. "starts on the layer it was asked for once the frame answers" pins the happy path.
  • Samples past the end: the recording clock itself is capped at the layer's end (lastTime), so samples and the shown duration stop there. That covers unsealed too, where only the runtime's seek was capped. The playhead row now asserts the last sample is at 0.5 s for a recording from 2 s on a layer ending at 2.5 s; 123c67a recorded 0.9 s.

The touched hook files pass 3 runs in a row (32 tests); Studio src/hooks and src/components/editor pass (4,046); Studio typecheck is clean.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Frame snapping can still put a saved sample past the layer end. The tick now clamps elapsed time, but useGestureRecording.ts:145–147 rounds that time to the nearest composition frame before saving it. I changed the new boundary test to start at 2 s with the layer ending at 2.52 s. The seek correctly stopped at 2.52 s, but the last sample was 0.533333 s at 30 fps, and the commit derives its duration from that sample. Please keep the final saved sample at or before the boundary after snapping, and pin an off-frame end in the test.

The pending-start guards address the earlier stale-reply finding. All 27 targeted tests passed before the off-frame variation.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in d7abc12: when snapping to the nearest frame would put a sample past the layer end, recordSample takes the frame before, so the last saved sample is at or before the boundary.

New row in useGestureRecording.sealed.test.tsx, "saves no sample past a layer end that falls between frames", records from 2 s on a layer ending at 2.52 s at 30 fps. The seek stops at 2.52 s and the last sample is 0.5 s. It fails on 8c9abab (0.533 s). The touched hook files pass 3 runs in a row (33 tests), Studio src/hooks and src/components/editor pass (4,047), and typecheck is clean.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sample stays on its nearest frame when that frame fits and uses the previous frame when rounding would exceed the layer end. The regression now checks the 2.52 s off-frame boundary alongside the existing on-frame case. All 28 targeted gesture tests passed locally. Required CI is still running.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reviewed gesture files are byte-for-byte identical after the merge. The producer's packed limit stays in place, and the new unpacked limit is the verifier's prescribed 5% headroom over the reported 3,526,322 bytes. Three focused verifier tests passed, and feeding the reported sizes to the verifier fails the old limit and passes the new one. I did not repack locally. Required CI is still running.

— tai (automated review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants